/*
 * motor_para.h
 *
 *  Created on: 2024年11月5日
 *      Author: zizhong
 */

#ifndef CONTROLLIB_MOTOR_PARA_H_
#define CONTROLLIB_MOTOR_PARA_H_

#ifndef PI
#define PI 3.14159265358979
#endif

#define M_BASE_VOLTAGE          13.86 // Base peak phase voltage (volt),
                                       // maximum measurable Vdc/sqrt(3)
#define M_BASE_SHUNT_CURRENT    6.0   // Base peak phase current (amp),
                                       // maximum measurable peak curr.
#define M_BASE_CURRENT          8.0   // Base peak phase current (amp),
                                       // maximum measurable peak current
#define M_MAXIMUM_VOLTAGE       36.0   // DC bus maximum voltage (V)

#define M_MINIMUM_VOLTAGE       24.0     // DC bus minimum voltage (V)

#define ADC_RESOLUTION              4096.0F             // 2^12, 12bits
#define ADC_PU_SCALE_FACTOR         0.000244140625F     // 1/2^12, 12bits ADC
#define ADC_PU_PPB_SCALE_FACTOR     0.000488281250F     // 1/2^11, 12bits ADC

//
// Analog scaling with ADC
//
#define M_ADC_PU_SCALE_FACTOR          0.000244140625     // 1/2^12
#define M_ADC_PPB_PU_SCALE_FACTOR      0.000488281250     // 1/2^11

//
// Current Scale
//
#define M_ADC_SCALE_CURRENT            M_BASE_CURRENT * 2.0
#define M_CURRENT_SENSE_SCALE          (M_ADC_SCALE_CURRENT / 4096.0)

//
// Voltage Scale
//
#define M_ADC_SCALE_VOLATGE            M_BASE_VOLTAGE * 1.732050808
#define M_VOLTAGE_SENSE_SCALE          (M_ADC_SCALE_VOLATGE / 4096.0)

//
// PWM, SAMPLING FREQUENCY and Current Loop Band width definitions
//
#define M_PWM_FREQUENCY           10.0   // in KHz
#define M_ISR_FREQUENCY           (M_PWM_FREQUENCY)

#define M_INV_PWM_TICKS         ((100 / 10) * 1000)
#define M_INV_PWM_DB            (150.0)

#define M_INV_PWM_TBPRD         (M_INV_PWM_TICKS / 2)
#define M_INV_PWM_HALF_TBPRD    (M_INV_PWM_TBPRD / 2)
#define M_SAMPLING_FREQ         (M_ISR_FREQUENCY * 1000)
#define M_CUR_LOOP_BANDWIDTH    (2.0F * PI * M_SAMPLING_FREQ / 25)

#define M_TPWM_CARRIER          (1000.0 / M_PWM_FREQUENCY)    //in uSec


// FCL Computation time
#define M_FCL_COMPUTATION_TIME  (2.00)  //in uS

#define M_MAXIMUM_CURRENT       12.0     // Motor maximum torque current (amp)


#define M_MAXIMUM_FREQ          50.0   // Motor maximum frequency (Hz)
#define M_STARTUP_FREQ          5.0    // Motor startup frequency (Hz)
#define M_BASE_FREQ             200.0     // Base electrical frequency (Hz)

#define M_ID_START      0.05            // alignment reference d-axis current
#define M_ID_RUN        0.0             // alignment reference d-axis current



#define M_RS            0.28            // 相电阻，Stator resistance (ohm)
#define M_RR            NULL            // Rotor resistance (ohm)
#define M_LS            0.0002          // 相电感，Stator inductance (H)
#define M_LD            M_LS            // Stator d-axis inductance (H)
#define M_LQ            M_LS            // Stator q-axis inductance (H)
#define M_LR            NULL            // Rotor inductance (H)
#define M_LM            NULL            // Magnetizing inductance (H)
#define M_KB            0.093            // BEMF Constant (V/Hz)
#define M_POLES         10               // Number of poles

#define ABS_POS_PU_SCALE   0.0000076294
#define IQ_START 0.05




#endif /* CONTROLLIB_MOTOR_PARA_H_ */
